package com.jsm.tf.service;

import com.jsm.tf.net.NettyClient;
import com.jsm.tf.net.message.request.CreateRoomMessage;
import com.jsm.tf.net.message.request.ListRoomMessage;
import com.jsm.tf.net.message.response.ListRoomResponseMessage;
import com.jsm.tf.room.RoomDTO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoomService {
    @Resource
    private NettyClient nettyClient;

    public void createRoom(String name) {
        CreateRoomMessage createRoomMessage = new CreateRoomMessage();
        createRoomMessage.setRoomName(name);
        nettyClient.sendMsg(createRoomMessage);
    }


    public List<RoomDTO> listRoom(int page, int pageSize) {
        ListRoomMessage listRoomMessage = new ListRoomMessage();
        listRoomMessage.setPage(page);
        listRoomMessage.setPageSize(pageSize);
        ListRoomResponseMessage listRoomResponseMessage = nettyClient.sendSyncMsg(listRoomMessage);
        if(listRoomResponseMessage==null){
            return null;
        }
        return listRoomResponseMessage.getRoomList();
    }
}
